import {  Body,Controller,Post, Param, Patch, Delete, Get, UseGuards  } from '@nestjs/common';
import { ProductService } from './product.service'
import { CreateProductDTO } from './product.dto';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
import {ApiOperation} from '@nestjs/swagger';
type ToggleProductStatusDTO = {
  isPublished: boolean;
};


type UpdateSkuStockDTO = {
  quantity: number;
  operation: 'INBOUND' | 'OUTBOUND';
  remark?: string;
};


@Controller('product')
export class ProductController {
    constructor(private readonly productService: ProductService) { }
  @UseGuards(JwtAuthGuard)
  @Post('create')
  async createProduct(@Body() dto: CreateProductDTO) {
    return this.productService.createProduct(dto);
  }
  @ApiOperation({ summary: '调整商品上下架' })
  @Patch(':id/status')
  async toggleProductStatus(
    @Param('id') productId: number,
    @Body() dto: ToggleProductStatusDTO
  ) {
    console.log(12345)
    return this.productService.toggleProductStatus(productId, dto.isPublished);
  }
  @UseGuards(JwtAuthGuard)
  @ApiOperation({ summary: '修改商品' })
  @Patch('skus/:id/stock')
  async updateSkuStock(
    @Param('id') skuId: number,
    @Body() dto: UpdateSkuStockDTO
  ) {

    console.log('stock:start')
    return this.productService.updateSkuStock(
      skuId,
      dto.quantity,
      dto.operation,
      dto.remark
    );
  }
   @UseGuards(JwtAuthGuard)
  @Delete(':id')
  async deleteProduct(@Param('id') productId: number) {
    return this.productService.deleteProduct(productId);
  }
  @UseGuards(JwtAuthGuard)
  @Get(':id')
  async getProductDetails(@Param('id') productId: number) {
    return this.productService.getProductDetails(productId);
  }

}
